<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>pinkish</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="pinker.html" title="pinker" />
    <link rel="next" href="pitch.html" title="pitch" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">pinkish</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="pinker.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="pitch.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="pinkish"></a>
      <div class="titlepage"></div>
      <a id="IndexPinkish" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">pinkish</span>
        </h2>
        <p>pinkish — 
      Generates approximate pink noise.
          </p>
      </div>
      <div class="refsect1">
        <a id="idp134284000"></a>
        <h2>Description</h2>
        <p>
      Generates approximate pink noise (-3dB/oct response) by one of two different methods:
      </p>
        <div class="itemizedlist">
          <ul class="itemizedlist" style="list-style-type: disc; ">
            <li class="listitem">
              <p>a multirate noise generator after Moore, coded by Martin Gardner</p>
            </li>
            <li class="listitem">
              <p>a filter bank designed by Paul Kellet</p>
            </li>
          </ul>
        </div>
        <p>
   </p>
      </div>
      <div class="refsect1">
        <a id="idp134287376"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ares <span class="command"><strong>pinkish</strong></span> xin [, imethod] [, inumbands] [, iseed] [, iskip]</pre>
      </div>
      <div class="refsect1">
        <a id="idp134338912"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>imethod</em></span> (optional, default=0) -- selects filter method: 
      </p>
        <div class="itemizedlist">
          <ul class="itemizedlist" style="list-style-type: disc; ">
            <li class="listitem">
              <p>0 = Gardner method (default).</p>
            </li>
            <li class="listitem">
              <p>1 = Kellet filter bank.</p>
            </li>
            <li class="listitem">
              <p>2 = A somewhat faster filter bank by Kellet, with less accurate response.</p>
            </li>
          </ul>
        </div>
        <p>
    </p>
        <p>
      <span class="emphasis"><em>inumbands</em></span> (optional) -- only effective with Gardner method. The number of noise bands to generate. Maximum is 32, minimum is 4. Higher levels give smoother spectrum, but above 20 bands there will be almost DC-like slow fluctuations.  Default value is 20.
    </p>
        <p>
      <span class="emphasis"><em>iseed</em></span> (optional, default=0) -- only effective with Gardner method. If non-zero, seeds the random generator. If zero, the generator will be seeded from current time. Default is 0.
    </p>
        <p>
      <span class="emphasis"><em>iskip</em></span> (optional, default=0) -- if non-zero, skip (re)initialization of internal state (useful for tied notes).  Default is 0.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp134347248"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>xin</em></span> -- for Gardner method: k- or a-rate amplitude. For Kellet filters: normally a-rate uniform random noise from rand (31-bit) or unirand, but can be any a-rate signal. The output peak value varies widely (±15%) even over long runs, and will usually be well below the input amplitude. Peak values may also occasionally overshoot input amplitude or noise.
    </p>
        <p>
      <span class="emphasis"><em>pinkish</em></span> attempts to generate pink noise (i.e., noise with equal energy in each octave), by one of two different methods.
    </p>
        <p>
      The first method, by Moore &amp; Gardner, adds several (up to 32) signals of white noise, generated at octave rates (sr, sr/2, sr/4 etc). It obtains pseudo-random values from an internal 32-bit generator. This random generator is local to each opcode instance and seedable (similar to <span class="emphasis"><em>rand</em></span>).
    </p>
        <p>
      The second method is a lowpass filter with a response approximating -3dB/oct. If the input is uniform white noise, it outputs pink noise. Any signal may be used as input for this method.  The high quality filter is slower, but has less ripple and a slightly wider operating frequency range than less computationally intense versions. With the Kellet filters, seeding is not used.
    </p>
        <p>
      The Gardner method output has some frequency response anomalies in the low-mid and high-mid frequency ranges. More low-frequency energy can be generated by increasing the number of bands. It is also a bit faster.  The refined Kellet filter has very smooth spectrum, but a more limited effective range. The level increases slightly at the high end of the spectrum.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp134355376"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the pinkish opcode. It uses the file <a class="ulink" href="examples/pinkish.csd" target="_top"><em class="citetitle">pinkish.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp134357040"></a>
          <p class="title">
            <strong>Example 628. Example of the pinkish opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in    No messages</span>
-odac           -iadc     -d     <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o pinkish.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="comment">; Initialize the global variables.</span>
<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">kr</span> <span class="op">=</span> 4410
<span class="ohdr">ksmps</span> <span class="op">=</span> 10
<span class="ohdr">nchnls</span> <span class="op">=</span> 1

<span class="comment">; Instrument #1.</span>
<span class="oblock">instr</span> 1
  awhite <span class="opc">unirand</span> 2.0

  <span class="comment">; Normalize to +/-1.0</span>
  awhite <span class="op">=</span> awhite <span class="op">-</span> 1.0  

  apink  <span class="opc">pinkish</span> awhite, 1, 0, 0, 1

  <span class="opc">out</span> apink <span class="op">*</span> 30000
<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="comment">; Play Instrument #1 for one second.</span>
<span class="stamnt">i</span> 1 0 1
<span class="stamnt">e</span>


<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />

      Kellet-filtered noise for a tied note (<span class="emphasis"><em>iskip</em></span> is non-zero).
    </p>
      </div>
      <div class="refsect1">
        <a id="idp134361664"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Authors: Phil Burk and John ffitch</td>
          </tr>
          <tr>
            <td>University of Bath/Codemist Ltd.</td>
          </tr>
          <tr>
            <td>Bath, UK</td>
          </tr>
          <tr>
            <td>May 2000</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in Csound Version 4.07</p>
        <p>
      Adapted for Csound by Rasmus Ekman
    </p>
        <p>
      The noise bands method is due to F. R. Moore (or R. F. Voss), and was presented by Martin Gardner in an oft-cited article in Scientific American. The present version was coded by Phil Burk as the result of discussion on the music-dsp mailing list, with significant optimizations suggested by James McCartney.
    </p>
        <p>
      The filter bank was designed by Paul Kellet, posted to the music-dsp mailing list.
    </p>
        <p>
      The whole pink noise discussion was collected on a HTML page by Robin Whittle, which is currently available at <a class="ulink" href="http://www.firstpr.com.au/dsp/pink-noise/" target="_top"><em class="citetitle">http://www.firstpr.com.au/dsp/pink-noise/</em></a>.
    </p>
        <p>Added notes by Rasmus Ekman on September 2002.</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="pinker.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="pitch.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">pinker </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> pitch</td>
        </tr>
      </table>
    </div>
  </body>
</html>
